www.gusucode.com > VC++ DES文件解密示例-源码程序 > VC++ DES文件解密示例-源码程序/code/DocDecyptDlg.cpp

    // DocDecyptDlg.cpp : implementation file
//  Download by http://www.NewXing.com

#include "stdafx.h"
#include "DocDecypt.h"
#include "DocDecyptDlg.h"
#include "stdlib.h"
#include "math.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class Decrypt :public CDialog{
public:
	static int IP_Table[64];      //初始置换(IP)
	static int E_Table[] ;//扩展变换E     
	static int S_Box[8][4][16];	//8个s盒
	static int IP_1_Table[64];//逆初始置换IP^-1
	static int P_Table[32] ;//置换运算P
	static int PC_1[56] ;  //密钥置换PC1  
	static int PC_2[48];//密钥置换PC_2
	static int move_times[16] ;       //对左移位的规定
	int K[16][48];			//存放16轮子密钥
	int c[64];				//存放明文或密文
	int L[17][32],R[17][32];  //存放加密过程中左右部分
	CString enCString;
public:
	void ToTwoBin(unsigned char p[8],int b[64])    //将字节转换成二进制流
	{
		int i,k=0;
		for(i=0;i<8;i++) 
		{
			int j=0x80;
			for(;j;j>>=1)  
			{
				if(j&p[i]) 
				{
					b[k++]=1;     
				}
				else   
				{
					b[k++]=0;   
				}
			}
		}    
	}
	
	void ToTow8(int a[],int b[],int n)    //八位二进制转成十进制
	{
		int i,j;
		int temp;
		int arry[8][8];
		int t=1,k;
		for(i=0;i<n/8;i++)
		{
			for(j=0;j<8;j++)
			{
				arry[i][j]=a[8*i+j];
			}
		}
		for (i=0;i<n/8;i++)
		{
			temp=0;
			for(j=7;j>=0;j--)
			{
				if(arry[i][j]==1)
				{
					t=1;
					for(k=0;k<7-j;k++)
					{
						t=t*2;
					}
					temp+=t;
				}
			}
			b[i]=temp;
		}	
	}

	void ToTwo4(int a[], int b[],int n)    //4位的二进制转十进制
	{
		int i,j;
		int temp;
		int arry[16][4];

		for(i=0;i<n/4;i++)
		{
			for(j=0;j<4;j++)
			{
				arry[i][j]=a[4*i+j];
			}
		}
		for (i=0;i<n/4;i++)
		{
			temp=arry[i][0]*8+arry[i][1]*4+arry[i][2]*2+arry[i][3]*1;
			b[i]=temp;
		}	
	}

	void Replacement(int arry1[],int arry2[],int arry3[],int num)			//置换函数,初始IP,逆初始IP。arry1[]需要置换数据, arry2[]置换函数, arry3[]转换后的,num代表多少位
	{
		int i,tmp;
		for(i=0;i<num;i++)
		{
			tmp=arry2[i];
			arry3[i]=arry1[tmp];  //按照IP的顺放置数据
		}
	}

	void Lif_move(int arry1[],int arry2[],int n)     //左移位实现函数  arry1[]需要左移的数组,arry2[]左移完后的,n左移的位数
	{
		int i;
		for(i=0;i<28;i++)
		{
			arry2[i]=arry1[(n+i)%28];
		}
	}

	void S_compress(int arry[],int shc[])	//S盒压缩变换,其中数组shc存放经过s盒的结果
	{
		int h,l;			//行,列
		int sha[8];            //存放经过s盒的十进制结果
		int i,j;
		int temp[4];

		for(i=0;i<8;i++) //s盒压缩变换
		{
			h=arry[(1+(i*6))-1]*2 + arry[(6+(i*6))-1];  //s盒接收6位的输出 将 6位输人中的第 1 位和第6位,形成一个两位二进制(0-3)作为行数
			l =arry[(2+(i*6))-1]*8 + arry[(3+(i*6))-1]*4 + arry[(4+(i*6))-1]*2 + arry[(5+(i*6))-1]; //将6位输入的中间4位构成一个二进制数(0-15)为列数
			sha[i]=S_Box[i][h][l];
		} 
		for(i=0;i<8;i++)    //8个6位数据连在一起,形成32位输出
		{
		   for(j=3;j>=0;j--)
		   {
			   temp[j]=sha[i]%2;
			   sha[i]=sha[i]/2;
		   }
		   for(j=0;j<4;j++)
		   {
			   shc[4*i+j]=temp[j];
		   }
		}
	}

	void F_Function(int a[32],int b[32],int n)	//密码函数F
	{
		int i;
		int tmp[48];
		int tep[32];
		Replacement(a,E_Table,tmp,48);			//扩展变换E
		for(i=0;i<48;i++)					//与子密钥异或
		{
			tmp[i]^= K[n][i];
		}
		S_compress(tmp,tep);              //压缩变换S
		Replacement(tep,P_Table,b,32);   //置换运算P
	}
	void SubKey(int K0[64])    //获取密钥Ki
	{
		int i;
		int K1[56],K2[56];    
		int C[17][28],D[17][28];         //置换输出的C表示前28位部分,D表示后28位部分
		Replacement(K0,PC_1,K1,56);  	//密钥置换PC_1(按PC_1上的数据顺序放置)
		for(i=0;i<28;i++)		//将PC_1输出的56比特分为左右两部分
		{
			C[0][i]=K1[i];
			D[0][i]=K1[i+28];
		}
		i=0;
		while(i<16)
		{
			int j;
			Lif_move(C[i],C[i+1],move_times[i]);   //调用左移函数
			Lif_move(D[i],D[i+1],move_times[i]);   //调用左移函数
			for(j=0;j<28;j++)
			{
				K2[j]=C[i+1][j];
				K2[j+28]=D[i+1][j];
			}
			Replacement(K2,PC_2,K[i],48);		//密钥置换PC_2 ,PC_2为压缩置换
			i++;
		}
	}

	void Anti_Key(int a[16][48])      //把解密密钥准备
	{
		int i,j;
		int tmp[16][48];
		
		for(i=0;i<16;i++)
		{
			for(j=0;j<48;j++)
			{
				tmp[i][j]=a[i][j];
			}
		}
		for(i=0;i<16;i++)  //因为解密是反过来,是用第i次迭代用17-i迭代生成的密钥月数据异或,准备异或的密钥
		{
			for(j=0;j<48;j++)
			{
				K[i][j]=tmp[15-i][j];
			}
		}

	}

	void Encryption(int m0[64],int c1[64])  //加密函数
	{
		int i,k;
		int arry[32];
		int c0[64],m1[64];
		Replacement(m0,IP_Table,m1,64);  //初始置换IP
		for(i=0;i<32;i++) 
		{
			L[0][i]=m1[i];
			R[0][i]=m1[i+32];
		}
		k=1;
		while(k<17)   //把第i-1次得到的的L和R的值作为第i次的输入数据
		{
			F_Function(R[k-1],arry,k-1);
			for(i=0;i<32;i++)
			{
				L[k][i]=R[k-1][i];
				R[k][i]=L[k-1][i]^arry[i];
			}
			k++;
		}
		for(i=0;i<32;i++)
		{
			c0[i]=R[16][i];
			c0[i+32]=L[16][i];
		}
		Replacement(c0,IP_1_Table,c1,64);   //逆初始置换
	}

	void Decryption(int c1[],int m[])  //解密函数
	{
		int c0[64],t[64];
		int i,k;
		int arry[32];
		Anti_Key(K);
		Replacement(c1,IP_Table,c0,64);		//初始IP
		for(i=0;i<32;i++)
		{
			L[0][i]=c0[i];
			R[0][i]=c0[i+32];
		}
		k=1;
		while(k<17)  //把第i-1次得到的的L和R的值作为第i次的输入数据
		{
			F_Function(R[k-1],arry,k-1);
			for(i=0;i<32;i++)
			{
				L[k][i]=R[k-1][i];
				R[k][i]=L[k-1][i]^arry[i];
			}
			k++;
		}
		for(i=0;i<32;i++)
		{
			t[i]=R[16][i];
			t[i+32]=L[16][i];
		}
		Replacement(t,IP_1_Table,m,64);   //逆初始置换
	}
	int CharDeC(char str[3])
	{
		double x=0;
		double N=0;
		double len=2;
		for (int i=0;i<len;)
		{		
			
			char  h=str[i];		
			x=HexChar(h);
			N+=x*(pow(16,(len-i-1)));
			i++;
			
		}
		return  N;
	}
	char HexChar(char c)
	{
		if ((c>='0')&&(c<='9'))
			
			return c-0x30;
		else if ((c>='A')&&(c<='F'))
			
			return c-'A'+10;
		
		else if ((c>='a')&&(c<='f'))
			
			return c-'a'+10;
		else
			AfxMessageBox("错误的数字");
		return 0x0;
		
		
	}
	CString FileDecript(CString filePath,CString savePath,unsigned char pwd[8])//解密文件
	{
		CString rtnStr="解密成功!";
		FILE *fp,*sp;
		FILE *tempFile = tmpfile();
		CString tempFileName=filePath.Left(filePath.ReverseFind('.'));
		savePath+=tempFileName.Right(tempFileName.GetLength()-tempFileName.ReverseFind('\\'));
		if((fp=fopen(filePath,"r+"))==NULL||(sp=fopen(savePath,"wb+"))==NULL||!tempFile){
			return "打开文件失败!";
		}
		int charNumber=0;
		int pwdTwoBinArr[64];
		ToTwoBin(pwd,pwdTwoBinArr);
		char encryptCharArr[3];
		boolean isFirst=true;
		char leftNum='0';
		while(fgets(encryptCharArr,3,fp)){
			charNumber++;
			char Bin[32];
			int a=CharDeC(encryptCharArr);
			itoa(a,Bin,2);
			ParseToC(Bin,charNumber-1);//将2进制转为字符
			if(charNumber==8){
				SubKey(pwdTwoBinArr);
				int reciew[64];
				Decryption(this->c,reciew);
				int sss[8];
				ToTow8(reciew,sss,64);
				if(isFirst){
					CString ddd="";
					for(int i=0;i<8;i++)
					{	
						ddd+=(unsigned char)sss[i];
					}
					if(ddd.Compare("thlofdlu")!=0){
						rtnStr="密码错误!";
						break;
					}
					isFirst=false;
					
				}else{
					for(int i=0;i<8;i++)
					{	
						leftNum=(unsigned char)sss[i];
						unsigned char ch=(unsigned char)sss[i];
						fwrite(&ch,sizeof(ch),1,tempFile);
					}
				}
				charNumber=0;
			}
		}
		int a=atoi(&leftNum);
		int reduceNum=8;
		if(a!=0){
			reduceNum+=8-a;
		}
		fseek(tempFile,0,SEEK_END);
		long filelength= ftell(tempFile)-reduceNum;
		fseek(tempFile,0,SEEK_SET);
		unsigned char temp;
		long count=0;
		while(count<filelength){
			count++;
			fread(&temp,sizeof(unsigned char), 1,tempFile);
			fwrite(&temp,sizeof(temp),1,sp);
		}
		fclose(tempFile);
		fclose(fp);
		fclose(sp);
		return rtnStr;
	}
	void ParseToC(char Bin[32],int position){
		int num=0;
		int newNum=7;
		char newC[8]={'0','0','0','0','0','0','0','0'};
		while(Bin[num++]!=NULL);
		for(int i=num-2;i>=0;i--){
			newC[newNum--]=Bin[i];
		}
		num=0;
		for(int j=position*8;j<position*8+8;j++){
			this->c[j]=newC[num++]-'0';
		}
	}

};
int Decrypt::IP_Table[64]={
	57, 49, 41, 33, 25, 17, 9, 1,
	59, 51, 43, 35, 27, 19, 11, 3,
	61, 53, 45, 37, 29, 21, 13, 5,
	63, 55, 47, 39, 31, 23, 15, 7,
	56, 48, 40, 32, 24, 16, 8, 0,
	58, 50, 42, 34, 26, 18, 10, 2,
	60, 52, 44, 36, 28, 20, 12, 4,
	62, 54, 46, 38, 30, 22, 14, 6
};
int Decrypt::E_Table[] = {			    	//扩展变换E
	   31,  0,  1,  2,  3,  4,
		3,  4,  5,  6,  7,  8,
		7,  8, 9, 10, 11, 12,
	   11, 12, 13, 14, 15, 16,
	   15, 16, 17, 18, 19, 20,
	   19, 20, 21, 22, 23, 24,
	   23, 24, 25, 26, 27, 28,
	   27, 28, 29, 30, 31,  0
};
                                   
int Decrypt::S_Box[8][4][16]  = {												//8个s盒
					{
						{14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7},
						{ 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8},
						{ 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0},
						{15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13}
					},

					{
						{15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10},
						{ 3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5},
						{ 0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15},
						{13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9}
					},

					{
						{10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8},
						{13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1},
						{13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7},
						{ 1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12}
					},

					{
						{ 7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15},
						{13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9},
						{10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4},
						{ 3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14}
					},

					{
						{ 2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9},
						{14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6},
						{4, 2, 1, 11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14},
						{11,8,12, 7, 1,14, 2,13,  6,15, 0, 9,10, 4, 5, 3}
					},

					{
						{12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11},
						{10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8},
						{ 9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6},
						{ 4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13}
					},

					{
						{ 4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1},
						{13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6},
						{ 1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2},
						{ 6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12}
					},

					{
						{13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7},
						{ 1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2},
						{ 7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8},
						{ 2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11}
					}
				};

int Decrypt::IP_1_Table[64] =						//逆初始置换IP^-1
{ 
    39, 7, 47, 15, 55, 23, 63, 31,
    38, 6, 46, 14, 54, 22, 62, 30,
    37, 5, 45, 13, 53, 21, 61, 29,
    36, 4, 44, 12, 52, 20, 60, 28,
    35, 3, 43, 11, 51, 19, 59, 27,
    34, 2, 42, 10, 50, 18, 58, 26,
    33, 1, 41, 9, 49, 17, 57, 25,
    32, 0, 40, 8, 48, 16, 56, 24
};

int Decrypt::P_Table[32] =				//置换运算P
{
	15,6,19,20,
	28,11,27,16,   
    0,14,22,25,
	4,17,30,9,   
    1,7,23,13,
	31,26,2,8,   
    18,12,29,5,
	21,10,3,24
}; 

int Decrypt::PC_1[56] =
 {
	56,48,40,32,24,16,8,   //密钥置换PC_1
    0,57,49,41,33,25,17,   
    9,1,58,50,42,34,26,   
    18,10,2,59,51,43,35,   
    62,54,46,38,30,22,14,   
    6,61,53,45,37,29,21,   
    13,5,60,52,44,36,28,   
    20,12,4,27,19,11,3
};   
  
int Decrypt::PC_2[48] =			//密钥置换PC_2
{
	13,16,10,23,0,4,
	2,27,14,5,20,9,
	22,18,11,3,25,7,
	15,6,26,19,12,1,   
    40,51,30,36,46,54,
	29,39,50,44,32,47,
	43,48,38,55,33,52,
	45,41,49,35,28,31
};  
int Decrypt::move_times[16] = {1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1};
class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDocDecyptDlg dialog

CDocDecyptDlg::CDocDecyptDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDocDecyptDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDocDecyptDlg)
	m_FilePath = _T("");
	m_FileSavePath = _T("");
	m_PassWord = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDocDecyptDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDocDecyptDlg)
	DDX_Control(pDX, IDC_PASSWORD, m_PassWordControl);
	DDX_Control(pDX, IDC_SAVE_BTN, m_SaveBtn);
	DDX_Control(pDX, IDC_DECRYPT_BTN, m_DecryptBtn);
	DDX_Text(pDX, IDC_FILE_PATH, m_FilePath);
	DDX_Text(pDX, IDC_FILE_SAVE_PATH, m_FileSavePath);
	DDX_Text(pDX, IDC_PASSWORD, m_PassWord);
	DDV_MaxChars(pDX, m_PassWord, 7);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDocDecyptDlg, CDialog)
	//{{AFX_MSG_MAP(CDocDecyptDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BROSWER, OnBroswer)
	ON_BN_CLICKED(IDC_SAVE_BTN, OnSaveBtn)
	ON_EN_CHANGE(IDC_PASSWORD, OnChangePassword)
	ON_BN_CLICKED(IDC_DECRYPT_BTN, OnDecryptBtn)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDocDecyptDlg message handlers

BOOL CDocDecyptDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	m_FilePath=_T("加密文件路径");
	m_FileSavePath=_T("设置解密后文件保存路径");
	m_PassWord=_T("输入密匙");
	UpdateData(false);
	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDocDecyptDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CDocDecyptDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CDocDecyptDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDocDecyptDlg::OnBroswer() 
{
	CFileDialog FileDialog(true, "*.gzs", "", OFN_EXPLORER,  "gzs Fliex(*.gzs)|*.gzs||", this);         //显示对话框      
	if(FileDialog.DoModal() == IDOK)       
    {           
		m_FilePath = FileDialog.GetPathName();
		m_PassWord=_T("");
        m_PassWordControl.SetReadOnly(false);
		m_PassWordControl.SetFocus();
		UpdateData(FALSE);     
	}
}

void CDocDecyptDlg::OnSaveBtn() 
{
	// TODO: Add your control notification handler code here
	char szDisplayName[MAX_PATH]; // 当前文件夹名字
	char szFullPath[MAX_PATH]; // 当前文件夹路径
	BROWSEINFO bi = {0}; 
	bi.hwndOwner = NULL; 
	bi.pidlRoot = NULL; 
	bi.pszDisplayName = szDisplayName; // 注意,这里必须是一个变量,如果赋值一个字符串常量,便会出现异常,
	
	// 因为当前文件夹的名字要返回在这里。
	bi.lpszTitle = _T("请选择一个文件夹"); 
	bi.ulFlags = BIF_RETURNFSANCESTORS|BIF_RETURNONLYFSDIRS; 
	bi.lpfn = NULL; 
	bi.lParam = NULL; 
	LPITEMIDLIST lpItemIDList = ::SHBrowseForFolder(&bi);
	if(lpItemIDList != NULL)
	{
		::SHGetPathFromIDList(lpItemIDList, szFullPath);
		m_FileSavePath=szFullPath;
		m_DecryptBtn.EnableWindow(true);
	}
	UpdateData(false);
}

void CDocDecyptDlg::OnChangePassword() 
{
	UpdateData(true);
	if(m_PassWord.GetLength()>0){
		m_SaveBtn.EnableWindow(true);
	}else{
		m_SaveBtn.EnableWindow(false);
		m_DecryptBtn.EnableWindow(false);
	}
	
}

void CDocDecyptDlg::OnDecryptBtn() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	int pl=m_PassWord.GetLength();
	for(int i=0;i<(8-pl);i++){
		m_PassWord+="2";
	}
	unsigned char pwd[9];
	int strLength = m_PassWord.GetLength() + 1;
    strncpy((char *)pwd, m_PassWord, strLength);
	Decrypt dn;
	MessageBox(dn.FileDecript(m_FilePath,m_FileSavePath,pwd));
}